﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace JapaneseMusicHtmlCreator
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        Frame framef = null;
        Frame framet = null;
        readonly double aniTime = 0.3;
        public PageWelcome pageWelcome = null;
        public PageInformation pageInformation = null;
        public PageKashiEdit pageKashiEdit = null;
        public PageSettings pageSettings = null;
        public PageCreateAndSave pageCreateAndSave = null;
        public MediaPlayer mediaPlayer = null;
        public string savedSettingsPath = null;
        public string musicTitle = null;
        public string musicArtist = null;
        public string musicPath = null;
        private string musicbkgndpath = null;
        private string musicbkgndpath2 = null;
        public string musicBkgndPath {
            get{
                return musicbkgndpath;
            }
            set{
                if (!string.IsNullOrEmpty(value))
                {
                    if (!value.Equals("delete"))
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            pageSettings.btnDelete.Visibility = Visibility.Visible;
                        });

                        musicbkgndpath = value;
                    }
                    else
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            pageSettings.btnDelete.Visibility = Visibility.Hidden;
                        });
                        musicbkgndpath = null;
                    }
                }
                
            }
        }
        public string musicBkgndPath2
        {
            get
            {
                return musicbkgndpath2;
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    if (!value.Equals("delete"))
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            pageSettings.btnDelete2.Visibility = Visibility.Visible;
                        });

                        musicbkgndpath2 = value;
                    }
                    else
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            pageSettings.btnDelete2.Visibility = Visibility.Hidden;
                        });
                        musicbkgndpath2 = null;
                    }
                }

            }
        }
        public string musicKashi = null;
        public double musicBkgndValue = 0;
        public bool musicBkgndUseBlack = false;
        public Color musicKashiColor = Colors.Black;
        public Color musicTranslateColor = Colors.Black;
        public Color musicKanaColor = Colors.Black;
        public Color musicCurrentKashiColor = Colors.Black;
        public Color musicTitleColor = Colors.Black;
        public Color musicArtistColor = Colors.Black;
        public Color musicBackgroundColor = Colors.White;
        public double musicLineFontSize = 0;
        public double musicCurrentLineFontSize = 0;
        public double musicLineAnimeTime = 0;
        public double musicTitleFontSize = 0;
        public double musicArtistFontSize = 0;
        public string musicHtmlText = null;
        public string createDir = null;
        public string musicType = null;
        public MainWindow()
        {
            InitializeComponent();
           
            pageWelcome = new PageWelcome(this);
            pageInformation = new PageInformation(this);
            pageKashiEdit = new PageKashiEdit(this);
            pageSettings = new PageSettings(this);
            pageCreateAndSave = new PageCreateAndSave(this);
            mediaPlayer = new MediaPlayer();
            mediaPlayer.Volume = 1;
            framef = new Frame();
            framet = new Frame();
            framef.NavigationUIVisibility = NavigationUIVisibility.Hidden;
            framet.NavigationUIVisibility = NavigationUIVisibility.Hidden;
            
      
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
           
            mainGrid.Children.Add(framef);
            mainGrid.Children.Add(framet);
            framef.Margin = new Thickness(800, 0, -800, 0);
            //
            framet.Content = pageWelcome;
            pageWelcome.LoadSettings();
            //framet.Content = pageWelcome;
            
            
           

           
        }

      

        public void NavigateForward(Page from, Page to)
        {
            framef.Content = from;
            framet.Content = to;
            ThicknessAnimation fromAni = new ThicknessAnimation(new Thickness(0, 0, 0, 0), new Thickness(-800, 0, 800, 0), TimeSpan.FromSeconds(aniTime));
            ThicknessAnimation toAni = new ThicknessAnimation(new Thickness(800, 0, -800, 0), new Thickness(0, 0, 0, 0), TimeSpan.FromSeconds(aniTime));
            framef.BeginAnimation(Frame.MarginProperty, fromAni);
            framet.BeginAnimation(Frame.MarginProperty, toAni);


        }
        public void NavigateBackward(Page from, Page to)
        {
            framef.Content = from;
            framet.Content = to;
            ThicknessAnimation fromAni = new ThicknessAnimation(new Thickness(0, 0, 0, 0), new Thickness(800, 0, -800, 0), TimeSpan.FromSeconds(aniTime));
            ThicknessAnimation toAni = new ThicknessAnimation(new Thickness(-800, 0, 800, 0), new Thickness(0, 0, 0, 0), TimeSpan.FromSeconds(aniTime));
            framef.BeginAnimation(Frame.MarginProperty, fromAni);
            framet.BeginAnimation(Frame.MarginProperty, toAni);
        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            System.Windows.Rect r = new Rect(e.NewSize);
            RectangleGeometry gm = new RectangleGeometry(r, 30, 30);
            RectangleGeometry gm2 = new RectangleGeometry(new Rect(0, 0, 60, 60));
            RectangleGeometry gm3 = new RectangleGeometry(new Rect(e.NewSize.Width-60, e.NewSize.Height-60, 60, 60));
            GeometryGroup group = new GeometryGroup();
            group.Children.Add(gm);
            group.Children.Add(gm2);
            group.Children.Add(gm3);
            group.FillRule = FillRule.Nonzero;
            ((UIElement)sender).Clip = group;
          
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.Close();
            }
        }



        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Label_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
           
          
            MessageBoxResult result = MessageBox.Show("是否关闭", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information);
            if (MessageBoxResult.Yes ==result )
            {
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;
            }
          
         
        }

        private void Window_LocationChanged(object sender, EventArgs e)
        {
        
        }

       
    }

    public enum Complete
    {
        None,Complete,Incomplete
    }
    public class JMH
    {
        public string musicTitle = null;//100
        public string musicArtist = null;//100
        public string musicPath = null;//1000
        public string musicBkgndPath = null;//1000
        public string musicKashi = null;//10000
        public double musicBkgndValue = 0;//8
        public bool musicBkgndUseBlack = false;//1
        public Color musicKashiColor = Colors.Black;//32
        public Color musicTranslateColor = Colors.Black;//32
        public Color musicKanjiColor = Colors.Black;//32
        public Color musicKanaColor = Colors.Black;//32
        public Color musicCurrentKashiColor = Colors.Black;//32
        public Color musicTitleColor = Colors.Black;//32
        public Color musicArtistColor = Colors.Black;//32
        public Color musicBackgroundColor = Colors.White;//32
        public double musicLineFontSize = 0;//8
        public double musicCurrentLineFontSize = 0;//8
        public double musicLineAnimeTime = 0;//8
        public double musicTitleFontSize = 0;//8
        public double musicArtistFontSize = 0;//8
    }


}
